from urllib import request,parse
from http import cookiejar

# 实例化
cookie = cookiejar.CookieJar()
cookie_handler = request.HTTPCookieProcessor(cookie)
http_hendler = request.HTTPHandler()
https_hendler = request.HTTPSHandler()

# 创建自定义请求方法
opener = request.build_opener(cookie_handler)
# 登录post提交,获取cookie
base_url = 'http://www.renren.com/PLogin.do'
def huya(msg,password):
    data = {
        'email':msg,
        'password':password
    }

    newdata = parse.urlencode(data)

    req = request.Request(url=base_url,data=bytes(newdata,encoding='utf-8'))

    # 发送请求 提交账号密码
    response = opener.open(req)

    # 向首页发送请求(重定向)
    home_index = 'http://www.renren.com/963734292'

    home_response = opener.open(home_index)

    html = home_response.read().decode('utf-8')
    print(html)

if __name__ == '__main__':
    msg = input('请输入账户:')
    password = input('请输入密码:')
    huya(msg,password)
